import { configureStore } from '@reduxjs/toolkit'
import themeReducer from './slices/theme'
import menuReducer from './slices/menu'
import { persistReducer, persistStore } from 'redux-persist'
import storage from 'redux-persist/lib/storage' // 默认使用localStorage

// 持久化配置
const persistConfig = {
  key: 'root', // 存储的键名
  storage, // 存储引擎
  // 可以选择性配置哪些reducer需要持久化
  whitelist: ['menuList'], // 只持久化counter
  // blacklist: ['someReducer'], // 不持久化someReducer
};

// 创建持久化的reducer
const persistedReducer = persistReducer(persistConfig, menuReducer);

export const store = configureStore({
  reducer: {
    theme: themeReducer,
    menu: persistedReducer
  },
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      serializableCheck: {
        ignoredActions: ['persist/PERSIST'], // 忽略redux-persist的action警告
      },
    }),
})

export const persistor = persistStore(store)

